﻿cmake_minimum_required(VERSION 3.5.1)

# 交叉编译时指定gcc版本
SET(CMAKE_C_COMPILER "/usr/bin/aarch64-linux-gnu-gcc")
SET(CMAKE_CXX_COMPILER "/usr/bin/aarch64-linux-gnu-g++")

project(yolov5_ascend)

# Compile options
add_compile_options(-std=c++11)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_CXX_FLAGS_DEBUG "-fPIC -O0 -g -Wall")
set(CMAKE_CXX_FLAGS_RELEASE "-fPIC -O2 -Wall")

# 指定Ascend推理包环境，根据实际路径修改
set(NNRT_PATH "/usr/local/Ascend/ascend-toolkit/latest")
set(NNRT_LIB_PATH "/usr/local/Ascend/ascend-toolkit/latest/acllib/lib64")
set(NNRT_LIB64_PATH "/usr/local/Ascend/ascend-toolkit/latest/lib64")

# OpenCV根目录
set(OPENCV_PATH ${CMAKE_SOURCE_DIR}/3rdparty/opencv4.3.0_arm64)
# ffmpeg根目录
set(FFMPEG_PATH ${CMAKE_SOURCE_DIR}/3rdparty/ffmpeg3.4.5_arm64)

# 根据实际路径修改nnrt推理包、OpenCV和ffmpeg头文件路径
include_directories(
    ${NNRT_PATH}/acllib/include
    ${NNRT_PATH}/include
    ${CMAKE_SOURCE_DIR}/include
    ${OPENCV_PATH}/include
    ${OPENCV_PATH}/include/opencv4
    ${FFMPEG_PATH}/include
)

# 链接nnrt、OpenCV和FFMPEG动态库动态库
link_directories(
    ${NNRT_LIB_PATH}
    ${NNRT_LIB64_PATH}
    ${FFMPEG_PATH}/lib
    ${OPENCV_PATH}/lib
)

add_executable(yolov5_ascend
    src/main.cpp
    src/yolov5_ascend.cpp
)

# 直接指定OpenCV动态库和ffmpeg动态库
target_link_libraries(yolov5_ascend
    opencv_core
    opencv_imgproc
    opencv_highgui
    opencv_imgcodecs
    opencv_videoio
    opencv_dnn
    avcodec
    avformat
    avutil
    swresample
    swscale
    ascendcl
    stdc++
    -lpthread -g
    )
